package com.chif.goingplus.controller;

import com.chif.goingplus.pojo.Bus;
import com.chif.goingplus.service.BusService;
import com.chif.goingplus.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping("/bus")
public class BusController {
    @Autowired
    private BusService busService;

    @RequestMapping("/add")
    public String addBus(Bus bus){
        return busService.addBus(bus)+"";
    }

    @RequestMapping("/delete")
    public String deleteBusById(int id){
        busService.deleteBusById(id);
        return "删除车辆信息成功";
    }

    @RequestMapping("/query")
    public String queryBusById(int id){
        return JsonUtils.getJson(busService.queryBusById(id));
    }

    @RequestMapping("/update")
    public String updateBus(Bus bus){
        busService.updateBus(bus);
        return "修改车辆信息成功";
    }

    @RequestMapping("/queryAll")
    public String queryAllBus(){
        return JsonUtils.getJson(busService.queryAllBus());
    }

}
